<%@ page language="java" pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="s" uri="http://www.springframework.org/tags"%>
<%@ page isELIgnored="false"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN">
<html>
  <head>
    <link rel="stylesheet" href="<s:url value="/resources"/>/css/innerstyle.css" type="text/css" />
    <link rel="stylesheet" type="text/css" media="screen" href="<s:url value="/resources"/>/css/cupertino/jquery-ui.custom.min.css" />
    <link rel="stylesheet" type="text/css" media="screen" href="<s:url value="/resources"/>/css/ui.jqgrid.css" />
    <link rel="stylesheet" type="text/css" media="screen" href="<s:url value="/resources"/>/css/ui.multiselect.css" />
    <script type="text/javascript" src="<s:url value="/resources"/>/js/jquery-1.7.2.min.js"></script>
    <script type="text/javascript" src="<s:url value="/resources"/>/js/jquery-ui.custom.min.js"></script> 
    <script type="text/javascript" src="<s:url value="/resources"/>/js/jquery.jqGrid.min.js"></script>
    <script type="text/javascript" src="<s:url value="/resources"/>/js/i18n/grid.locale-cn.js"></script>  
    <script type="text/javascript" src="<s:url value="/resources"/>/js/i18n/jquery.ui.datepicker-zh-CN.js"></script>
    <script type="text/javascript" src="<s:url value="/resources"/>/js/jquery.alerts.js"></script>
    <link rel="stylesheet" type="text/css" media="screen" href="<s:url value="/resources"/>/css/jquery.alerts.css" />
  </head>
  <style type="text/css">
    html,body {
	margin: 0;
	padding: 0;
	font-size: 85%;
  }
 </style>
  <script type="text/javascript">  
   $(function(){ 
	    $("#but_delete").button();    
	    $("#but_check").button();
	    //$("#but_saveall").button();
	    $("#but_tib").button();
	    //$("#but_tiball").button();
	    $("#but_excel").button();
	    var wenjid =  $("#wenjid").val() ;
	    loadTab(wenjid);    
  });
  
  //加载表
  function loadTab(wenjid){ 
      $("#myTab").jqGrid({  
		    url:'<s:url value="/hwjs"/>/findFydTemp?wenjid='+ wenjid,
		    datatype: 'json',
		    mtype: 'post',         
		   	colNames:['sysid','zhuangt','日期','铁路计划号','发货单位','矿厂','发站','收货单位','到站','煤种','品名','车数','吨数','状态','验证信息','zhuangt'],
		   	colModel:[
		      	{ name: 'sysid', index: 'sysid', width: 10, hidden: true },
		      	{ name: 'zhuangt', index: 'zhuangt', width: 10, hidden: true },
                { name: 'fayrq', index: 'fayrq', sortable: false, width: 80, editable: true },
                { name: 'pizhh', index: 'pizhh', sortable: false, width: 80, editable: true },
                { name: 'fahdw', index: 'fahdw', sortable: false, width: 250, editable: true },
                { name: 'kuangch', index: 'kuangch', sortable: false, width: 80, editable: true },
                { name: 'fazh', index: 'fazh', sortable: false, width: 60, editable: true },
                { name: 'shouhdw', index: 'shouhdw', sortable: false, width: 300, editable: true },
                { name: 'daozh', index: 'daozh', sortable: false, width: 60, editable: true },
                { name: 'meizh', index: 'meizh', sortable: false, width: 80, editable: true },
                { name: 'pinm', index: 'pinm', sortable: false, width: 60, editable: true },
                { name: 'faychsh', index: 'faychsh', sortable: false, width: 60, editable: true },
                { name: 'faydsh', index: 'faydsh', sortable: false, width: 50, editable: true },
                { name: 'isjiaoyan', index: 'zhuangt', sortable: false, width: 80, editable: true },
                { name: 'yanzxx', index: 'yanzxx', sortable: false, width: 250, editable: true },
                { name: 'zhuangt', index: 'zhuangt', sortable: false, width: 250, hidden: true }
		   	],
		   	multiselect: true, 
		   	multiboxonly: true,//只有点多选框才能多选
		    jsonReader: {
		           repeatitems : false, 
		           id: 'sysid'
		         },   
		    height:400, 
		    width:1300,
		    shrinkToFit: true, 	
		   	rowNum:10,
		   	rowList:[10,30,50],     	
		   	pager: '#pager',
		   	rownumbers: true,   	 
		    viewrecords: true,
		    //recordpos:'left',
		    sortname:'sysid',
		    sortorder: 'desc', 
		    caption: "发运单列表"	
	       });
	  }
  
	   //校验
		function checkFyd() {	
			var sysid = $("#myTab").jqGrid('getGridParam','selarrrow');
			if (sysid.length == 0)
			{
			    jAlert('请至少选择一条记录','提示');
			}
			else
			{
			var url = "<s:url value="/hwjs"/>/checkFyd?sysid="+sysid;
			$( "#dialog-confirm" ).dialog({
					resizable: false,
					height:140,
					modal: true,
					buttons: {
						"确认": function() {
							$.post(url, function(data) {
								var obj = eval('(' + data + ')');
								if(obj.success==true){
								        alert(obj.msg);
								        $("#myTab").trigger("reloadGrid");
								 }else{
								         alert(obj.msg);
								       }
		                   });
		                   $( this ).dialog( "close" ); 
						},
						"返回": function() {
							$( this ).dialog( "close" );
						}
					}
				});
			}
		}
		
		//批量提交
		function batchtij() {	
			var sysid = $("#myTab").jqGrid('getGridParam','selarrrow');
			if (sysid.length == 0)
			{
			    jAlert('请至少选择一条记录','提示');
			} else 
			{
			   var i = 0;
			   for(i=0;i<sysid.length;i++)
			      { 
			         var zhuangt= $("#myTab").getCell(sysid[i],"zhuangt");
			         alert(zhuangt);
			         if(zhuangt == 0)
			         {  
			             jAlert('不能提报包含未校验的数据，请点击校验','提示');
			             return false;
			         }
			         if(zhuangt == 2)
			         {  
			             jAlert('校验未通过，请修改后重新校验','提示');
			             return false;
			         }
			      }
			}
			
			/* if (sysid.length == 0)
			{
			    jAlert('请至少选择一条记录','提示');
			}
			else
			{
			var url = "<s:url value="/hwjs"/>/tijTempFydBatch?sysid="+sysid;
			$( "#dialog-confirm1" ).dialog({
					resizable: false,
					height:140,
					modal: true,
					buttons: {
						"确认": function() {
							$.post(url, function(data) {
								var obj = eval('(' + data + ')');
								if(obj.success==true){
								        //location.href ="<s:url value="/hwjs"/>/directHwjflr";
								        loadTab();
								 }else{
								         alert(obj.msg);
								       }
		                   });
		                   $( this ).dialog( "close" ); 
						},
						"返回": function() {
							$( this ).dialog( "close" );
						}
					}
				});
			} */
		}
	
	
</script>  
<body>  
<div id="best1">
  <div>
      <input type="button" value="删除" id="but_delete" onclick="" />
      <input type="button" value="校验数据" id="but_check" onclick="checkFyd();" />
      <!-- <input type="button" value="全部保存" id="but_saveall" onclick="" /> -->
      <input type="button" value="提报" id="but_tib" onclick="batchtij();" />
      <!-- <input type="button" value="全部提报" id="but_tiball" onclick="" /> -->
      <!-- <input type="button" value="导出EXCEL" id="but_excel" onclick="" /> -->
      <input type="hidden" name="wenjid" id="wenjid" value="${wenjid}" />
    </div>
    <br>
    <table id="list_search" cellpadding="0" cellspacing="0" border="0">
    </table>
    <table id="myTab" class="scroll" cellpadding="0" cellspacing="0" style="width:100%" ></table>  
   	<div id="pager" class="scroll"></div>  
   	<div id="dialog-confirm" title="是否确认校验？"></div> 
   	<div id="dialog-confirm-tibao" title="是否确认提报？"></div> 
</div> 
</body>
</html>
